package com.primeton.eos.bizlet.lucene;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.primeton.tp.common.xml.XmlUtil;
import com.primeton.tp.core.bizservice.EOSParameter;
 

/**
 * PaodingBizLet �Ĳ����࣬��EOS Studio 5.0�Զ����
 * @version 1.0
 * @date 2008-4-2
 */

public class Test_LuceneClient {
	/**
	 * BL_getAnalyzerWords �Ĳ��Է���
	 * @throws Exception 
	 */
	public static void test_BL_Search() throws Exception{
		
		System.setProperty("PAODING_DIC_HOME", "D:/OpenSource/paoding-analysis");
		System.setProperty("EOS_HOME", "d:/primeton_eos/eosserver");
		System.setProperty("jboss.server.home.dir","d:/primeton_eos/jakarta-tomcat-5.0.28/server/default");
		EOSParameter para = new EOSParameter();
		para.setUnitName("TEST");
		para.setUnitId("0");
		
		//�������
		String xml = "<root><data><SEARCH_FILES/><list type='SEARCH_FILES'/></data></root>";
		Document doc = XmlUtil.parseString(xml);
		
		Element entity1 = (Element)XmlUtil.findNode(doc, "/root/data/SEARCH_FILES");
		Element entity2 = (Element)XmlUtil.findNode(doc, "/root/data/list[@type='SEARCH_FILES']");
		
		para.addObject(entity1, "EOSEntity");
		para.addObject(entity2, "EOSEntity");
		
		String indexLocation =  "D:/OpenSource/index";
		
    	Node tmphome = (Node) doc.createElement("INDEX_HOME");	 
		XmlUtil.setNodeValue(tmphome, indexLocation);

    	Node tmpstart = (Node) doc.createElement("START_VAL");	 
		XmlUtil.setNodeValue(tmpstart, "1");
		
    	Node tmpmax = (Node) doc.createElement("MAX_RESULTS");	 
		XmlUtil.setNodeValue(tmpmax, "10");		
		
    	Node tmpquery = (Node) doc.createElement("QUERY_STRING");	 
		XmlUtil.setNodeValue(tmpquery, "普元");				
		
		entity1.appendChild(tmphome);
		entity1.appendChild(tmpstart);
		entity1.appendChild(tmpmax);
		entity1.appendChild(tmpquery);
		
		String str = XmlUtil.node2String(entity1);
		System.out.println("str="+str);
 
 
		//TODO: Enter your test code here
		 LuceneClient.BL_SearchFiles(doc, para);
		 
		 entity2 = (Element)XmlUtil.findNode(doc, "/root/data/list[@type='SEARCH_FILES']");
		 
			String str2 = XmlUtil.node2String(entity2);
			System.out.println("str2="+str2);		 
		

		
	}	
	
	public static void test_BL_Index() throws Exception{
		
		System.setProperty("PAODING_DIC_HOME", "D:/OpenSource/paoding-analysis");
		System.setProperty("EOS_HOME", "d:/primeton_eos/eosserver");
		System.setProperty("jboss.server.home.dir","d:/primeton_eos/jakarta-tomcat-5.0.28/server/default");
		EOSParameter para = new EOSParameter();
		para.setUnitName("TEST");
		para.setUnitId("0");
		
		///�������
		String xml = "<root><data><INDEX_FILES/> <list type='SEARCH_FILES'/></data></root>";
		Document doc = XmlUtil.parseString(xml);
		
		Element entity1 = (Element)XmlUtil.findNode(doc, "/root/data/INDEX_FILES");
		Element entity2 = (Element)XmlUtil.findNode(doc, "/root/data/list[@type='SEARCH_FILES']");
		
		para.addObject(entity1, "EOSEntity");
		para.addObject(entity2, "EOSEntity");
		
		String indexHome =  "D:/OpenSource/index";
		String dataHome =  "D:/OpenSource/search_data";
		
 
		
    	Node tmpIndexHome = (Node) doc.createElement("INDEX_HOME");	 
		XmlUtil.setNodeValue(tmpIndexHome, indexHome);

    	Node tmpSearchHome = (Node) doc.createElement("DATA_HOME");	 
		XmlUtil.setNodeValue(tmpSearchHome, dataHome);
		
 		
		
		entity1.appendChild(tmpIndexHome);
		entity1.appendChild(tmpSearchHome);
 
		
		String str = XmlUtil.node2String(entity1);
		System.out.println("str="+str);
 
 
		//TODO: Enter your test code here
		 LuceneClient.BL_IndexFiles(doc, para);
		 
 
		

		
	}		


	public static void main(String[] args) {
		try {
			 
			Test_LuceneClient.test_BL_Index();
			 Test_LuceneClient.test_BL_Search();
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
